
package com.service.impl;


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import com.dao.CommonDao;
import com.service.CommonService;


/**
 * 系统用户
 */
@Service("commonService")
public class CommonServiceImpl implements CommonService {

  @Resource
  StringRedisTemplate stringRedisTemplate;

  @Autowired
  private CommonDao commonDao;

  @Override
  public List<String> getOption(Map<String, Object> params) {
    String tableName =
        StrUtil.toString(params.get("table")) + ":" + StrUtil.toString(params.get("column"));
    // 先从 redis 中获取值，如果redis中没有，就先从 MySQL中获取，然后存入redis，最后返回
    List<String> list = stringRedisTemplate.opsForList().range(tableName, 0, -1);
    if (CollectionUtil.isEmpty(list)) {
      list = commonDao.getOption(params);
      stringRedisTemplate.opsForList().rightPushAll(tableName, list);
    }
    return list;
  }

  @Override
  public Map<String, Object> getFollowByOption(Map<String, Object> params) {
    return commonDao.getFollowByOption(params);
  }

  @Override
  public void sh(Map<String, Object> params) {
    commonDao.sh(params);
  }

  @Override
  public int remindCount(Map<String, Object> params) {
    return commonDao.remindCount(params);
  }

  @Override
  public Map<String, Object> selectCal(Map<String, Object> params) {
    return commonDao.selectCal(params);
  }

  @Override
  public List<Map<String, Object>> selectGroup(Map<String, Object> params) {
    return commonDao.selectGroup(params);
  }

  @Override
  public List<Map<String, Object>> selectValue(Map<String, Object> params) {
    return commonDao.selectValue(params);
  }

  @Override
  public List<Map<String, Object>> selectTimeStatValue(Map<String, Object> params) {
    return commonDao.selectTimeStatValue(params);
  }

}
